/* 
	@Copyright (c) 2007 by Denis Riabtchik. All rights reserved. See license.txt and http://jgrouse.com for details@
	$Id: Vocabulary.java 600 2013-04-15 01:24:07Z denis.riabtchik@gmail.com $
*/

package jgrouse.jgdoc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public enum Vocabulary
{
	
	CONTENT (TokenType.CONTENT),
	
	FILE (TokenType.PHYS_CONTAINER, true),
	MODULE (TokenType.PHYS_CONTAINER, true),
	PACKAGE (TokenType.PHYS_CONTAINER, true),
	
	CLASS (TokenType.LOGICAL_CONTAINER, true, Modifiers.s_standardModifiers),
	STRUCT (TokenType.LOGICAL_CONTAINER, true, Modifiers.s_standardModifiers),
	NAMESPACE (TokenType.LOGICAL_CONTAINER, true),
	INTERFACE (TokenType.LOGICAL_CONTAINER, true, Modifiers.s_standardModifiers),
	OBJECT (TokenType.LOGICAL_CONTAINER, true, Modifiers.s_standardModifiers),
	
	FUNCTION (TokenType.FUNCTION, true, true, Modifiers.s_standardModifiers),
	//FUNC(FUNCTION),
	METHOD(FUNCTION),
	CONSTRUCTOR (TokenType.FUNCTION, true, Modifiers.s_constrModifiers),
	IFUNCTION (TokenType.FUNCTION, true, true, Modifiers.s_standardModifiers),
	EVENT (TokenType.FUNCTION, true, true, Modifiers.s_standardModifiers),
	//IFUNC (IFUNCTION),
	//SIG (IFUNCTION),
	
	VARIABLE (TokenType.VARIABLE, true, true, Modifiers.s_varModifiers),
	VAR (VARIABLE),
	PROPERTY (TokenType.VARIABLE, true, true, Modifiers.s_varModifiers),
	//PROP (PROPERTY),
	
	AUTHOR (TokenType.GEN_MULT_ATTR),
	SEE (TokenType.GEN_MULT_ATTR, true, false, true, false, true),
	EXAMPLE (TokenType.GEN_MULT_ATTR),
	
	VERSION (TokenType.GEN_SINGLE_ATTR),
	SINCE (TokenType.GEN_SINGLE_ATTR),
	DEPRECATED (TokenType.GEN_SINGLE_ATTR),
	GEN_SINGLE_ATTRS (TokenType.GEN_SINGLE_ATTR),
	TIMESTAMP (TokenType.GEN_SINGLE_ATTR),
	
	CONTEXT (TokenType.FUNC_SINGLE_ATTR, false, true),
	PARAM (TokenType.FUNC_MULT_ATTR, true, true, Modifiers.s_paramModifiers),
	PARAMOPTION (TokenType.FUNC_MULT_ATTR, true, true, Modifiers.s_varModifiers),
	PARAMSET (TokenType.FUNC_MULT_ATTR),
	THROWS (TokenType.FUNC_MULT_ATTR, true, false, true),
	//EXCEPTION (THROWS),
	RETURNS (TokenType.FUNC_MULT_ATTR),
	RETURN (RETURNS),
	INHERITDESC (TokenType.MEMBER_SINGLE_ATTR),
	
	EXTENDS (TokenType.CLASS_MULT_ATTR, true, false, true),
	IMPLEMENTS (TokenType.CLASS_MULT_ATTR, true, false, true),
	
	REQUIRES (TokenType.MODULE_MULT_ATTR, true, false, true),
	
	SCOPE (TokenType.CONTROL, true),
	END (TokenType.CONTROL),
	
	PROJECT (TokenType.PROJECT,  false, false, false, true),
	DESCRIPTION (TokenType.PROJECT_ATTR);
	
	
	
	private TokenType m_tokenType;
	private boolean m_allowsType;
	private boolean m_requiresName;
	private boolean m_nameAsLink;
	private List<String> m_modifiers;
	private Vocabulary m_base;
	private boolean m_nameAsDesc;
	private boolean m_allowExternalLink;
	private boolean m_allowsName = true;
	


	public boolean isAllowsName() {
		return m_allowsName;
	}


	private Vocabulary(TokenType tokenType)
	{
		m_tokenType = tokenType;
	}
	
	
	private Vocabulary(TokenType tokenType, boolean requiresName)
	{
		m_tokenType = tokenType;
		m_requiresName = requiresName;
	}
	
	private Vocabulary(TokenType tokenType, boolean requiresName, String[] modifiers)
	{
		m_tokenType = tokenType;
		m_requiresName = requiresName;
		setModifiers(modifiers);
		
	}
	
	private Vocabulary(TokenType tokenType, boolean requiresName, boolean allowsType)
	{
		m_tokenType = tokenType;
		m_requiresName = requiresName;
		m_allowsType = allowsType;
	}
	
	private Vocabulary(TokenType tokenType, boolean requiresName, boolean allowsType, String[] modifiers)
	{
		m_tokenType = tokenType;
		m_requiresName = requiresName;
		m_allowsType = allowsType;
		setModifiers(modifiers);
	}
	
	private Vocabulary(TokenType tokenType, boolean requiresName, boolean allowsType, boolean nameAsLink)
	{
		m_tokenType = tokenType;
		m_requiresName = requiresName;
		m_allowsType = allowsType;
		m_nameAsLink = nameAsLink;
	}
	
	private Vocabulary(TokenType tokenType, boolean requiresName, boolean allowsType, boolean nameAsLink, boolean nameAsDesc)
	{
		m_tokenType = tokenType;
		m_requiresName = requiresName;
		m_allowsType = allowsType;
		m_nameAsLink = nameAsLink;
		m_nameAsDesc = nameAsDesc;
	}

	private Vocabulary(TokenType tokenType, boolean requiresName, boolean allowsType, boolean nameAsLink, boolean nameAsDesc, boolean allowExternalLink)
	{
		m_tokenType = tokenType;
		m_requiresName = requiresName;
		m_allowsType = allowsType;
		m_nameAsLink = nameAsLink;
		m_nameAsDesc = nameAsDesc;
		m_allowExternalLink = allowExternalLink;
	}
	
	
	private Vocabulary(Vocabulary pBase)
	{
		m_allowsType = pBase.m_allowsType;
		m_base = pBase;
		m_modifiers = pBase.m_modifiers;
		m_nameAsLink = pBase.m_nameAsLink;
		m_requiresName = pBase.m_requiresName;
		m_tokenType = pBase.m_tokenType;
	}
	
	public TokenType getTokenType()
	{
		return m_tokenType;
	}

	public boolean isAllowsType()
	{
		return m_allowsType;
	}

	public boolean isRequiresName()
	{
		return m_requiresName;
	}

	public boolean isNameAsLink()
	{
		return m_nameAsLink;
	}

	public List<String> getModifiers()
	{
		return m_modifiers;
	}

	public void setModifiers(String[] pModifiers)
	{
		m_modifiers = pModifiers != null? new ArrayList<String>(Arrays.asList(pModifiers)) : null;
	}
	
	public String toString()
	{
		if (m_base != null)
		{
			return m_base.toString();
		}
		return super.toString();
	}


	public boolean isNameAsDesc()
	{
		return m_nameAsDesc;
	}
	
	public boolean isAllowExternalLink() {
		return m_allowExternalLink;
	}

	public boolean isPlainContent() {
		return !(m_allowExternalLink || m_allowsType || m_nameAsDesc || m_nameAsLink || m_requiresName || m_modifiers != null);
	}
	
	static {
		CONTEXT.m_allowsName = false;
	}
	
}